﻿using K8.EF;
using System.Linq.Expressions;
using System.Reflection.Metadata;
using KingerRobot.PCRMES.Dao;
using System.Collections.Generic;

namespace KingerRobot.PCRMES.SpiService;

public class WmsCheckRepositories : IWmsCheckRepositories
{
    #region 同步方法
    public i_wms_check QueryById(string id)
    {
        var _db = Db.Default;
        return _db.WmsCheck.FirstOrDefault(d => d.check_id == id);
    }

    /// <summary>
    /// 功能描述:根据ID查询数据
    /// 作　　者:Robin
    /// </summary>
    /// <param name="lstIds">id列表,如果是联合主键，请使用Where条件</param>
    /// <returns>数据实体列表</returns>
    public List<i_wms_check> QueryByIDs(object[] lstIds)
    {
        var _db = Db.Default;
        return _db.WmsCheck.Where(d => lstIds.Contains(lstIds)).ToList();
    }

    /// <summary>
    /// 更新实体数据
    /// </summary>
    /// <param name="entity">博文实体类</param>
    /// <returns></returns>
    public int Update(i_wms_check entity)
    {
        var _db = Db.Default;
        return _db.WmsCheck.Update<i_wms_check>(entity);
    }
    /// <summary>
    /// 待条件更新所有数据
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <param name="entity"></param>
    /// <returns></returns>
    public int Update(Expression<Func<i_wms_check, bool>> whereExpression, i_wms_check entity)
    {
        var _db = Db.Default;
        return _db.WmsCheck.Where(whereExpression).Update(new i_wms_check
        {
            update_flag= entity.update_flag,
            last_modified_time = entity.last_modified_time,
            last_modified_user = entity.last_modified_user
        });
    }

    /// <summary>
    /// 正序查询第一条数据
    /// </summary>
    /// <returns></returns>
    public i_wms_check First()
    {
        var _db = Db.Default;
        return _db.WmsCheck.First();
    }
    /// <summary>
    /// 查询第一条数据
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    public i_wms_check First(Expression<Func<i_wms_check, bool>> whereExpression)
    {
        var _db = Db.Default;
        if (whereExpression == null) return null;
        return _db.WmsCheck.Where(whereExpression).FirstOrDefault();
    }


    /// <summary>
    /// 功能描述:查询所有数据
    /// 作　　者:Robin
    /// </summary>
    /// <returns>数据列表</returns>
    public List<i_wms_check> Query()
    {
        List<i_wms_check> list = null;
        try
        {
            var _db = Db.Default;
            list= _db.WmsCheck.ToList();
            return list;
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Query执行异常:{ex.Message}");
        }
        return list;
    }


    /// <summary>
    /// 功能描述:查询数据列表
    /// 作　　者:Robin
    /// </summary>
    /// <param name="whereExpression">whereExpression</param>
    /// <returns>数据列表</returns>
    public List<i_wms_check> Query(Expression<Func<i_wms_check, bool>> whereExpression)
    {
        var _db = Db.Default;
        if (whereExpression == null) return null;
        return _db.WmsCheck.Where(whereExpression).ToList();
    }
    #endregion
}
